package com.iteaj.iot.builder;

import com.iteaj.iot.ChannelManager;
import com.iteaj.iot.FrameworkComponent;
import com.iteaj.iot.ProtocolHandle;
import com.iteaj.iot.codec.filter.Filter;

import java.util.ArrayList;
import java.util.List;

public class ComponentBuilder<T extends ProtocolHandle, F extends Filter> {

    private F filter;
    private Builder builder;
    private ChannelManager manager;
    private FrameworkComponent component;
    private List<ProtocolHandle> handles = new ArrayList<>();

    public ComponentBuilder(FrameworkComponent component, Builder builder) {
        this.builder = builder;
        this.component = component;
    }

    public Builder use() {
        return this.builder;
    }

    /**
     * 组件使用的过滤器(可选)
     * @param filter
     * @return
     */
    public ComponentBuilder<T, F> filter(F filter) {
        this.filter = filter; return this;
    }

    /**
     * 协议处理器(可选)
     * @param handle
     * @return
     */
    public ComponentBuilder<T, F> register(T handle) {
        this.handles.add(handle); return this;
    }

    /**
     * 设备管理器(可选)
     * @param manager
     * @return
     */
    public ComponentBuilder<T, F> deviceManager(ChannelManager manager) {
        this.manager = manager; return this;
    }

    protected F getFilter() {
        return filter;
    }

    protected FrameworkComponent getComponent() {
        return component;
    }
}
